import { defineStore } from "pinia";
import { reqHospitalDetail, reqHospitalDeparment } from "@/api/hospital";
import type { HospitalDetail } from "@/api/hospital/type";
import type { DetailState } from './interface'
import type { HosPitalDetail, DeparmentResponseData, DeparmentArr } from "@/api/hospital/type";
const useDetailStore = defineStore('Detail', {
    state: (): DetailState => {
        // @ts-ignore
        return {
            // 医院详情的数据
            hospitalInfo: ({} as HosPitalDetail),
            // 存储医院科室的数据
            deparmentArr: ([] as DeparmentArr)
        }
    },
    actions: {
        // 获取医院详情的方法
        async getHospital(hoscode: string) {
            let { code, data }: HospitalDetail = await reqHospitalDetail(hoscode)
            if (code === 200) {
                this.hospitalInfo = data
            }
        },
        // 获取某一个医院科室的数据
        async getDeparment(hoscode: string) {
            let { code, data }: DeparmentResponseData = await reqHospitalDeparment(hoscode)
            if (code === 200) {
                this.deparmentArr = data
            }
        }
    },
    getters: {}
});

export default useDetailStore